package com.example.lvsuo.controller;

import com.example.lvsuo.entity.Log;
import com.example.lvsuo.entity.vo.LogVo;
import com.example.lvsuo.modal.Result;
import com.example.lvsuo.service.ILogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 <p>
 * 案件 前端控制器
 * </p>
 *
 * @author 欢喜
 * @since 2021-04-28
 */
@RestController
@RequestMapping("/log")
public class LogController {
    @Autowired
    ILogService iLogService;

    /**
     * 查询客户案件
     * @param logVo
     * @return
     */
    @GetMapping
    public Result getLogClient(LogVo logVo){
        PageHelper.startPage(logVo.getPageId(),logVo.getPageNum());
        PageInfo pageInfo = new PageInfo(iLogService.getLogClient(logVo));
        return Result.back("ok","200",pageInfo);
    }

    /**
     * 查询案件
     * @param logVo
     * @return
     */
    @GetMapping(params = "chaxun=1")
    public Result getLog(LogVo logVo){
        PageHelper.startPage(logVo.getPageId(),logVo.getPageNum());
        PageInfo pageInfo = new PageInfo(iLogService.getLog(logVo));
        return Result.back("ok","200",pageInfo);
    }
    /**
     * 根据id查询案件
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getLogId(@PathVariable String id){
        List<Log> list=iLogService.getLogId(id);
        return Result.back("ok","200",list);
    }

    /**
     * 修改
     * @param log
     * @return
     */
    @PutMapping
    Result updateLog(@RequestBody Log log) {
        System.out.println(log);
        iLogService.updateById(log);//添加用户
        return Result.back("ok", "200");
    }

}
